package cn.edu.scau.cmi.liguanwu.safecomposite;

import java.util.HashSet;
import java.util.Set;

public class Team extends Orangization{
	private Orangization Parent;
	private String name;
	private Set<Orangization> children=new HashSet<Orangization>();
	@Override
	public void doSomething() {
			System.out.println("This is Team "+name+".");
			if(Parent!=null) {
				System.out.println("	We blong to "+((Team)Parent).getName());
			}
			if(children.size()>0)
				for (Orangization item : children) {
	                 if(item.getClass()==Team.class) {
	                	 System.out.println("	Team "+item.getName()+" do good jobs.");
	                 }
	                 else if(item.getClass()==Person.class) {
	                	 System.out.println("	Person "+item.getName()+" do good jobs.");
	                 }
			    }
	}
	public void setParent(Orangization Parent) {
	    this.Parent=Parent;
	}
	@Override
	public Orangization getParent() {
		return this.Parent;
	}
	public Orangization getperson(String nam) {
		Orangization tmp=null;
		if(children.size()>0)
			for (Orangization item : children) {
				if(item.getClass()==Person.class&&nam.equals(item.getName())) {
					tmp=item;
				}
			}
		return tmp;
	}
	public Orangization addChild(Orangization child){
		children.add(child);
		return this;
	}
	public Orangization removeChild(Orangization child){
		children.remove(child);
		return this;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
